package com.wish.algorithm;

/**
 * Created by suliucheng on 2021/4/16 21:49
 * Directions:
 */
public class ShortestPath {

    public static int height = 8;
    public static int width = 7;
    /**
     * 初始化一个地图
     */
    public static int[][] mapArr = new int[height][width];

    static {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                mapArr[0][j] = 2;
                mapArr[height - 1][j] = 2;
                mapArr[i][0] = 2;
                mapArr[i][width - 1] = 2;
            }
        }
        mapArr[3][1] = 2;
        mapArr[3][2] = 2;
    }

    /**
     * 定义一个起始位置
     */
    private int[] start = {1, 1};
    /**
     * 定义一个终点位置
     */
    private int[] end = {6, 5};
    /**
     * 初始化一个球
     */
    private int[] ball = start;

    public void move() {
        if (ball[0] == end[0] && ball[1] == end[1]) {
            System.out.println("小球已经到达终点。");
            return;
        }
        if (ball[0] < end[0]) {
            if (ball[0] == 2 && (ball[1] == 1 || ball[1] == 2)) {
            }else{
                ball = goDown(ball);
            }
        }
        if (ball[1] < end[1]) {
            ball = goRight(ball);
        }
        move();
    }

    private int[] goDown(int[] ball) {
        ball[0] = ball[0] + 1;
        System.out.println("小球向下移动了一次,此刻小球的坐标为:" + ball[0] + "," + ball[1]);
        return ball;
    }


    private int[] goRight(int[] ball) {
        ball[1] = ball[1] + 1;
        System.out.println("小球向右移动了一次,此刻小球的坐标为:" + ball[0] + "," + ball[1]);
        return ball;
    }


}
